package com.wfg.beanfactorypostprocessor;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.stereotype.Component;

/**
 * spring
 *
 * @Title: com.wfg.beanfactorypostprocessor
 * @Date: 2021/1/1 0001 21:49
 * @Author: wfg
 * @Description:
 * @Version:
 */
//@Component
public class MyBeanFactoryProcessor implements BeanFactoryPostProcessor {
	@Override
	public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
		System.out.println("====postProcessBeanFactory====");
		String[] beanDefinitionNames = beanFactory.getBeanDefinitionNames();
		for (String beanName:beanDefinitionNames ) {
			System.out.println("beanName  :  "+beanName);
			if("userDaoImpl".equals(beanName)){
				BeanDefinition userDaoImpl = beanFactory.getBeanDefinition(beanName);
				userDaoImpl.setScope(ConfigurableBeanFactory.SCOPE_PROTOTYPE);
			}
		}
	}
}
